import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/common/Home'
import Login from '@/components/pages/Login'
import Menus from '@/components/pages/Menus'
// 门诊病例
import Demo from '@/components/pages/Demo'

Vue.use(Router)
const router = new Router({
  routes: [{
    path: '/',
    redirect: {
      name: 'login'
    }
  }, {
    path: '/login',
    name: 'login',
    component: Login
  }, {
    path: '/',
    name: 'home',
    component: Home,
    // meta: {
    //   requiresAuth: true
    // },
    children: [{
        path: '/menus',
        name: 'menus',
        component: Menus
      },
      {
        path: '/demo',
        name: 'demo',
        component: Demo
      }
    ]
  }]
})

// router.beforeEach((to, from, next) => {
//   if (to.matched.some(record => record.meta.requiresAuth)) { // 判断哪些需要验证token
//     if (!localStorage.getItem("name")) { // token存在条件
//       next({
//         path: '/login'
//       })
//     } else {
//       next()
//     }
//   } else {
//     next() // 确保一定要调用 next()
//   }
// })

export default router
